<?php
class LibraryTestCase extends Zend_Test_PHPUnit_ControllerTestCase
{
    /** @var Zend_Application */
    protected $application;
    
    /** @var Bisna\Service\ServiceLocator */
    protected $_serviceLocator;
    
    protected $_validEmail = "inskips@gmail.com";
    protected $_validPassword = "5k1ppy";
    protected $_invalidUser = "no@user.com";
    protected $_invalidPassword = "badpass";
    
    public function setUp()
    {
        $this->bootstrap = array($this, 'appBootstrap');
        $this->_initAutoloader();
        $this->_initServiceLoader();
        parent::setUp();
    }
    
    public function appBootstrap()
    {
        $this->application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
        $this->application->bootstrap();
        
        $bootstrap = $this->application->getBootstrap();
        $front = $bootstrap->getResource('FrontController');
        $front->setParam('bootstrap', $bootstrap);
    }
    
    protected function _initAutoloader()
    {
        require_once APPLICATION_PATH . '/../library/Doctrine/Common/ClassLoader.php';
        
        $autoloader = \Zend_Loader_Autoloader::getInstance();
        
        $bisnaAutoloader = new \Doctrine\Common\ClassLoader('Bisna');
        $autoloader->pushAutoloader(array($bisnaAutoloader, 'loadClass'), 'Bisna');
        
        $appAutoloader = new \Doctrine\Common\ClassLoader('NOLASnowball');
        $autoloader->pushAutoloader(array($appAutoloader, 'loadClass'), 'NOLASnowball');
        
        $ccAutoloader = new \Doctrine\Common\ClassLoader('CC');
        $autoloader->pushAutoloader(array($ccAutoloader, 'loadClass'), 'CC');
    }
    
    protected function _initServiceLoader()
    {
    	$configDir      = APPLICATION_PATH . '/configs';
        $serviceLocator = $configDir . '/serviceLocator.ini';
        $services       = $configDir . '/services.ini';
        $doctrine       = $configDir . '/application.ini';

        $context   = new \Bisna\Service\Context\IniFileContext(array(
            'path' => $services
        ));
        
        $d2Config  = new \Zend_Config_Ini($doctrine, APPLICATION_ENV);
        $container = new \Bisna\Application\Container\DoctrineContainer(
            $d2Config->resources->doctrine->toArray()
        );

        $locator   = new Bisna\Service\ServiceLocator($context, $container);
        $loader    = new Bisna\Service\Loader\DefaultLoader($locator);
    	
        $this->_serviceLocator = $locator;
    }
}